package com.ys.timer;

import com.ys.service.business.TpShopAnalysisReportFormsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * 店铺运营分析
 */
@Controller
public class TimerTPShopAnalysisReportFormsMonth {
	private static final Logger logger = LoggerFactory.getLogger(TimerTPShopAnalysisReportFormsMonth.class);

	@Autowired
	private TpShopAnalysisReportFormsService tpShopAnalysisReportFormsService;


	//统计前一个月的数据
	@Scheduled(cron = "0 0 2 2 * ?")//每月2号2点触发任务
	//@Scheduled(cron = "5 * * * * * ")//开发测试用
	public void addhopRegisterPhaseRecordDailyByCompany() {
		try {
			logger.info("***********定时统计店铺运营分析表开始***********");
			//获取上个月时间
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.MONTH, -1);
			String oldMonth = sdf.format(calendar.getTime());//上个月
			//统计上个月的运营分析表数据，根据店铺
			tpShopAnalysisReportFormsService.add(oldMonth);
			//统计上个月的运营分析表数据，总和
			calendar.add(Calendar.MONTH, -1);
			String oldOldMonth = sdf.format(calendar.getTime());//上上个月
			tpShopAnalysisReportFormsService.addTotal(oldOldMonth);//上上个月
			tpShopAnalysisReportFormsService.addTotal(oldMonth);//上个月
			logger.info("***********定时统计店铺运营分析表完成***********");
		}catch (Exception e){
			//e.printStackTrace();
			logger.error("定时统计店铺运营分析表出错：",e);
		}

	}



}
